from datetime import datetime
from django.db import models, IntegrityError, transaction
from django.template.defaultfilters import slugify
from tagging.models import Tag
from common.models import NameSlugModel, DateAwareModel, MyImageModel, UserOwnedModel, LocationAwareModel

class Place(NameSlugModel, DateAwareModel):

    def __unicode__(self):
        return self.name

class Dish(NameSlugModel, DateAwareModel):
    place = models.ForeignKey(Place, null=True, blank=True)
    tags = models.ManyToManyField(Tag, null=True, blank=True) # dish can be a specific food or a combination of foods

    def __unicode__(self):
        return self.name

class PlaceImage(MyImageModel, UserOwnedModel):
    place = models.ForeignKey(Place)

class DishImage(MyImageModel, UserOwnedModel):
    dish = models.ForeignKey(Dish)

class Review(DateAwareModel, UserOwnedModel):
    text = models.TextField(blank=True)
    dish = models.ForeignKey(Dish)
    rating = models.IntegerField(blank=True, null=True)
    tags = models.ManyToManyField(Tag, null=True, blank=True)

    def __unicode__(self):
        return str(self.created_date) + ' ' + str(self.dish) + ' by ' + str(self.user)